package com.magicalcoder.pigeontest.server.common;

import com.magicalcoder.pigeon.common.callback.NettyStartSuccessCallback;
import com.magicalcoder.pigeon.ioc.PigeonBeanContainer;
import com.magicalcoder.pigeon.server.PigeonNettyServer;
import com.magicalcoder.pigeon.zookeeper.RegisterServer;
import com.magicalcoder.pigeontest.server.init.InitStart;
import com.magicalcoder.pigeontest.service.HelloPersonService;
import com.magicalcoder.pigeontest.service.HelloService;
import com.magicalcoder.pigeontest.service.impl.HelloPersonServiceImpl;
import com.magicalcoder.pigeontest.service.impl.HelloServiceImpl;
import org.apache.zookeeper.KeeperException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by hzhedongyu on 2017/5/27.
 * 无需zookeeper 简单快捷
 * 只要绑定了端口号 ip肯定是固定的 这样就确定了server的唯一
 * 同一台机器只能启动1个端口号
 */
public class ServerStart {

     private static Logger logger = LoggerFactory.getLogger(ServerStart.class);

    public static void main(String[] args) throws InterruptedException {
        InitStart initStart = new InitStart();
        initStart.init();

        System.out.println("start...");
        HelloPersonService helloPersonService = PigeonBeanContainer.getBean(HelloPersonServiceImpl.class);
        HelloService helloService = PigeonBeanContainer.getBean(HelloServiceImpl.class);
        Map<String,Object> kv = new HashMap<>();
        kv.put(HelloPersonService.class.getName(),helloPersonService);
        kv.put(HelloService.class.getName(),helloService);

        int port = 8880;//一个端口号肯定对应一种service service可能包含很多java service

        PigeonNettyServer server = new PigeonNettyServer(kv);
        server.start(port, new NettyStartSuccessCallback() {
            @Override
            public void call() {

            }
        });
    }
}